Skip to main content
Version: Next

MVVM Style

  • We are following the MVVM architecture in the plugin repo . All the features developed should follow the pattern and adhere to it.
  • All written feature should be 100% kotlin and in Jetpack compose

MVVM Summary

MVVM has 3 distinct layers

Alt text

  • Model : These are kotlin data classes, they are used to hold application data. Normally different models are used for diff purposes and there should exists extension functions/ extenstion properties which can map one model to another. For example for making an API call, you have two data classes a request and response data class. You might also have a third data class named ViewState which is used to render UI elements. The model layer also incorporates all business logic in our app which is often broken down into further layers
  • View : Those are android UI elements developed in compose that a user sees and interacts with
  • Viewmodel : These tranform models (API responses ) into view state models for the view to display. The Viewmodel is also responsible for handling user interactions passed through buy the view. It should have a compose function, 1 viewmodel per screen. Viewmodel classes will contain code which emits a viewstate for view to render, transforms API into a single viewstate class, responds to user interactions, emits one- off events using chanels which the compose view listens to. Viewmodel should never have reference to Android context/view classes.

Our MVVM style

We have a specific style of MVVM where each view has only 1 viewmodel and that viewmodel emits a single viewstate which represents every piece of data that a View can render. A more standard MVVM might have multiple view or multiple view states or data emited using live data/ flows

View should never ask the Viewmodel directly for data, instead data that the view renders comes from the view state only

Viewmodel does not interact with the view directly, it only emits a new viewstate

If we want to interact with the view from the viewmodel use viewEvents

Best Practises

  • All code be using Android best practises and Kotlin best practises